﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Sparrow.CMS
{
    using Sparrow.Extensions;
    using Sparrow.Web.Router;

    public class Widget
    {
        public string Name
        {
            get;
            set;
        }

        public Layout Layout
        {
            get;
            set;
        }


        public IEnumerable<string> GetActionNames(PageContent content)
        {
            return Facotry.Provider.GetActionNames(content, this);           
        }

        public bool Add(PageContent content,string actionName)
        {
            content.WebRouter.Add(new WebRouterModule() { Name = actionName });
            return Facotry.Provider.AddAction(content, this, actionName);
        }

        public bool Remove(PageContent content,string actionName)
        {
            content.WebRouter.Remove(new WebRouterModule() { Name = actionName });
            return Facotry.Provider.RemoveAction(content,this, actionName);
        }

        public IEnumerable<IAction> GetActions(PageContent content)
        {
            var actionNames = this.GetActionNames(content).ToArray();
            return Facotry.Actions.Where(i => actionNames.Contains(i.Name));            
        }
    }
}
